<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateShopsAndGoodsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('shops')) {
            //店铺
            Schema::create('shops', function(Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->default(0)->comment('用户id');
                $table->string('name')->nullable()->comment('店铺名称');
                $table->string('desc')->nullable()->comment('店铺简介');
                $table->integer('thumb_id')->default(0)->comment('缩略图');
                $table->string('contact')->nullable()->comment('联系电话');
                $table->string('contact_people')->nullable()->comment('联系人');
                $table->string('province',64)->nullable()->comment('省份');
                $table->string('city',64)->nullable()->comment('城市');
                $table->string('area',64)->nullable()->comment('地区');
                $table->string('address',64)->nullable()->comment('详细地址');
                $table->string('open_license')->nullable()->comment('营业执照');
                $table->integer('open_license_img_id')->default(0)->comment('营业执照的图片');
                $table->integer('sort')->default(0)->comment('排序 数值越小越靠前');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('goods')) {
            //商品信息表
            Schema::create('goods', function(Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('user_id')->default(0)->comment('发布者');
                $table->integer('shop_id')->default(0)->comment('店铺id');
                $table->string('ssn',20)->nullable()->comment('商品货号');
                $table->string('name',50)->comment('商品名称');
                $table->integer('integral')->default(0)->comment('购买商品所获积分');
                $table->decimal('m_price')->default(0)->comment('市场价格');
                $table->decimal('s_price')->default(0)->comment('销售价格');
                $table->integer('thumb_id')->default(0)->comment('商品缩略图');
                $table->string('info')->nullable()->comment('商品信息描述');
                $table->integer('stock')->default(0)->comment('商品库存');
                $table->integer('classify_id')->default(0)->comment('商品分类id');
                $table->text('detail')->nullable()->comment('商品详情');
                $table->integer('is_free_shipping')->default(0)->comment('是否包邮 0:不包邮 1：包邮');
                $table->integer('is_shop')->default(0)->comment('是否上架，0：否 1：是');
                $table->timestamp('shop_time')->nullable()->comment('上架时间');
                $table->integer('is_recommend')->default(0)->comment('是否推荐，0：否 1：是');
                $table->integer('is_selling')->default(0)->comment('是否热卖，0：否 1：是');
                $table->integer('sale_count')->default(0)->comment('销售数量');
                $table->integer('is_new')->default(0)->comment('是否新品，0：否 1：是');
                $table->integer('sort')->default(0)->comment('商品排序，整数，数字越低排序越前');
                $table->string('type')->nullable()->comment('common:常规商品;integral:积分商品;');
                $table->integer('exchange_integral')->default(0)->comment('兑换商品的积分');
                $table->string("link_url")->nullable()->comment('商品链接');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('goods_spu')) {
            /** 商品属性类型 */
            Schema::create('goods_spu', function (Blueprint $table) {
                $table->increments('id')->comment('自增id');
                $table->integer('goods_id')->default(0)->comment('商品id');
                $table->string('spu_name')->nullable()->comment('属性名');
                $table->decimal('price')->default(0)->comment('商品价格');
                $table->integer('stock')->default(0)->comment('商品库存');
                $table->integer('sort')->default(0)->comment('排序');
                $table->integer('status')->default(0)->comment('状态');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if (!Schema::hasTable('goods_banner')) {
            //商品轮播图
            Schema::create('goods_banner', function(Blueprint $table) {
                $table->increments('id');
                $table->integer('img_id')->default(0)->comment('banner图图片id');
                $table->integer('goods_id')->default(0)->comment('商品id');
                $table->integer('sort')->default(0)->comment('排序 数值越小越靠前');
                $table->softDeletes();
                $table->timestamps();
            });
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
